/**
 * 
 */
package com.manage.model;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
import java.util.Map.Entry;

import com.util.Loggable;


public class Project extends Loggable {

	private int id;
	private String name;
	private int channelId;
	private Date shipDate;
	private String shipDesc;

	// reserved
	private String pa;
	private String pb;
	private String pc;

	private Properties props;
	
	protected int status;
	
	public Project()
	{
		this.id = -1;
		this.name = "";
		this.channelId = -1;
		this.shipDate = new Date();
		this.shipDesc = "";
		
		this.pa = "";
		this.pb = "";
		this.pc = "";
		
		this.props = new Properties();

		this.status = 0;
	}
	
	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}
	/**
	 * @param id the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}
	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}
	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}
	/**
	 * @return the channelid
	 */
	public int getChannelId() {
		return channelId;
	}
	/**
	 * @param channelid the channelid to set
	 */
	public void setChannelId(int channelId) {
		this.channelId = channelId;
	}
	/**
	 * @return the status
	 */
	public int getStatus() {
		return status;
	}
	/**
	 * @param status the status to set
	 */
	public void setStatus(int status) {
		this.status = status;
	}
	/**
	 * @return the pa
	 */
	public String getPa() {
		return pa;
	}
	/**
	 * @param pa the pa to set
	 */
	public void setPa(String pa) {
		this.pa = pa;
	}
	/**
	 * @return the pb
	 */
	public String getPb() {
		return pb;
	}
	/**
	 * @param pb the pb to set
	 */
	public void setPb(String pb) {
		this.pb = pb;
	}
	/**
	 * @return the pc
	 */
	public String getPc() {
		return pc;
	}
	/**
	 * @param pc the pc to set
	 */
	public void setPc(String pc) {
		this.pc = pc;
	}

	public String getProps()
	{
		String p = "";
		for (Entry<Object, Object> e : props.entrySet())
		{
			if (p.length() >0)
				p += "&";
			p += (String) e.getKey() + "=" + (String) e.getValue();
		}
		return p;
	}
	
	public void setProps(String props)
	{
		this.props = new Properties();
		String[] ss = props.split("&");
		for (String s : ss)
		{
			s = s.trim();
			if (s.length() == 0)
				continue;
			
			String[] si = s.split("=", 2);
			if (si.length == 2)
				this.props.setProperty(si[0], si[1]);
			else
				this.props.setProperty(si[0], "");
		}
	}
	
	public void setProps(String key, String value)
	{
		this.props.setProperty(key, value);
	}
	
	public String getProps(String key)
	{
		return this.props.getProperty(key);
	}
	
	public Properties getProperties()
	{
		return this.props;
	}
	
	public void setProperties(Properties props)
	{
		this.props = props;
	}

	/**
	 * @param props the props to set
	 */
	public void setProps(Properties props) {
		this.props = props;
	}

	/**
	 * @return the shipDate
	 */
	public Date getShipDate() {
		return shipDate;
	}

	/**
	 * @param shipDate the shipDate to set
	 */
	public void setShipDate(Date shipDate) {
		this.shipDate = shipDate;
	}

	public void setShipDate(String shipDate) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		try {
			this.shipDate = sdf.parse(shipDate);
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * @return the shipDesc
	 */
	public String getShipDesc() {
		return shipDesc;
	}

	/**
	 * @param shipDesc the shipDesc to set
	 */
	public void setShipDesc(String shipDesc) {
		this.shipDesc = shipDesc;
	}
}
